package org.hxyjs.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Press;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.PressService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/pressController")
public class PressController {
	@Resource
	PressService pressService;
	@RequiresPermissions("press:getAll")
	@RequestMapping("/getAllPress")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Press> getAllPress() throws Exception {
    	System.out.println("查询全部出版社");
		return pressService.getAllPresss();
    }

	@RequestMapping("/deletePressByPrno/{prno}")
	@ResponseBody
    public DTO<Press> deletePressByPrno(@PathVariable("prno") String prno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(prno+"删除出版社");
    	return pressService.deletePressByPrno(prno);
    }

	@RequestMapping("/updatePressByPrno")
	@ResponseBody
	public DTO<Press> updatePressByPrno(@RequestBody Press press) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改出版社");
		return pressService.updatePressByPrno(press);
	}


	@RequestMapping("/addPress")
	@ResponseBody
	public DTO<Press> addPress(@RequestBody Press press) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加出版社");
		System.out.println(press);
 		return pressService.addPress(press);
	}
	@RequestMapping("/getPressByPage")
	@ResponseBody
	public DTO<Press> getPressByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页管理员");
		return pressService.getPressByPage(pageInfo);
	}

	@RequestMapping("/selectPressWithSalesagentAndBooks/{prno}")
	@ResponseBody
	public DTO<Press> selectPressWithSalesagentAndBooks(@PathVariable("prno") String prno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询成功");
		return pressService.selectPressWithSalesagentAndBooks(prno);
	}


}